package com.ruoyi.swla2.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.swla2.domain.BasicDyh;
import com.ruoyi.swla2.service.IBasicDyhService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 大用户配置Controller
 *
 * @author gdqt
 * @date 2023-06-16
 */
@RestController
@RequestMapping("/region/basicDyh")
public class BasicDyhController extends BaseController {
    @Autowired
    private IBasicDyhService basicDyhService;

    /**
     * 查询大用户配置列表
     */
    @PreAuthorize("@ss.hasPermi('region:basicDyh:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasicDyh basicDyh) {
        startPage();
        List<BasicDyh> list = basicDyhService.selectBasicDyhList(basicDyh);
        return getDataTable(list);
    }

    /**
     * 导出大用户配置列表
     */
    @PreAuthorize("@ss.hasPermi('region:basicDyh:export')")
    @Log(title = "大用户配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasicDyh basicDyh) {
        List<BasicDyh> list = basicDyhService.selectBasicDyhList(basicDyh);
        ExcelUtil<BasicDyh> util = new ExcelUtil<BasicDyh>(BasicDyh.class);
        util.exportExcel(response, list, "大用户配置数据");
    }

    /**
     * 获取大用户配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('region:basicDyh:query')")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID) {
        return success(basicDyhService.selectBasicDyhByID(ID));
    }

    @PreAuthorize("@ss.hasPermi('region:basicDfq:query')")
    @GetMapping(value = "/getBasicDyhByAreaId")
    public AjaxResult getBasicDyhByAreaId(@RequestParam("areaId") String areaId) {
        return success(basicDyhService.getBasicDyhByAreaId(areaId));
    }

    /**
     * 新增大用户配置
     */
    @PreAuthorize("@ss.hasPermi('region:basicDyh:add')")
    @Log(title = "大用户配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicDyh basicDyh) {
        basicDyh.setTenantId(this.getTenantId());
        return toAjax(basicDyhService.insertBasicDyh(basicDyh));
    }

    /**
     * 修改大用户配置
     */
    @PreAuthorize("@ss.hasPermi('region:basicDyh:edit')")
    @Log(title = "大用户配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicDyh basicDyh) {
        return toAjax(basicDyhService.updateBasicDyh(basicDyh));
    }

    /**
     * 删除大用户配置
     */
    @PreAuthorize("@ss.hasPermi('region:basicDyh:remove')")
    @Log(title = "大用户配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable Long[] IDs) {
        return toAjax(basicDyhService.deleteBasicDyhByIDs(IDs));
    }
}
